package com.woniu.controller;

import com.woniu.entity.Category;
import com.woniu.entity.PageResult;
import com.woniu.entity.dto.CategoryDTO;
import com.woniu.entity.vo.CategoryVO;
import com.woniu.service.CategoryService;
import com.woniu.utils.ResultObj;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Category)表控制层
 *
 * @author makejava
 * @since 2025-06-10 19:03:23
 */
@RestController
@RequestMapping("api/category")
@CrossOrigin
public class CategoryController {
    /**
     * 服务对象
     */
    @Autowired
    private CategoryService categoryService;

    /**
     * 获取全部课程信息
     * @return
     */
    @GetMapping("getCategoryAll")
    public ResultObj getCategoryAll(){
        List<CategoryVO> categoryVOList = categoryService.getCategoryAll();
        return ResultObj.ok(categoryVOList);
    }
    /**
     * 首页home轮播图的菜单
     */
    @GetMapping("/faceCategory")
    public ResultObj faceCategory(){
        List<CategoryDTO> categoryDTOS=categoryService.getMenuTree();
        System.out.println(ResultObj.ok(categoryDTOS));
        return ResultObj.ok(categoryDTOS);
    }
    /**
     * 添加课程分类信息
     */
    @PostMapping("addCategory")
    public ResultObj addCategory(@RequestBody Category category){
        categoryService.addCategory(category);
        return ResultObj.ok();
    }
    /**
     * 修改课程分类信息
     */
    @PutMapping("updCategory")
    public ResultObj updCategory(@RequestBody Category category){
        categoryService.updCategory(category);
        return ResultObj.ok();
    }
    /**
     * 删除节点及以下全部节点
     */
    @PutMapping("delCategoryByAll")
    public ResultObj delCategoryByAll(@RequestBody CategoryVO categoryVO){
        categoryService.delCategoryByAll(categoryVO);
        return ResultObj.ok();
    }
    /**
     * 多条件查询课程分类信息
     */
    @PostMapping("selCategoryByOne")
    public ResultObj selCategoryByOne(@RequestBody Category category){
        List<Category> categoryList = categoryService.selCategoryByOne(category);
        return ResultObj.ok(categoryList);
    }
    /**
     * 暂未开发
     * 删除单个分类节点
     */
    @PutMapping("delCategoryByOne")
    public ResultObj delCategoryByOne(@RequestBody CategoryVO categoryVO){
//        categoryService.delCategoryByOne();
        return ResultObj.ok();
    }
}

